package com.dom.domweb.modular.controller;

import com.dom.common.enums.VerfyStatEnum;
import com.dom.common.model.vo.stor.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.StorOrderService;
import com.dom.domweb.utils.TradeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 入库单控制层
 * @Author xllei
 * @Date 2018/12/21 2:30 PM
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/stor")
public class StorStockinController {
    @Autowired
    private StorOrderService storOrderService;

    @RequestMapping(value="/stockin/getStockinPager", method = RequestMethod.GET)
    public TabPager getStockinPager(@RequestParam("limit")int limit, @RequestParam("page")int page,
                                    @RequestParam("storCode")Integer storCode, @RequestParam("stockDate")String stockDate,
                                    @RequestParam("stockType")Integer stockType, @RequestParam("organCode") Integer organCode,
                                    @RequestParam("stat") Integer stat, @RequestParam("verfyStat") Integer verfyStat){
        S019R request = new S019R();
        TradeUtil.setHead(request);

        request.setPn(page);
        request.setPs(limit);
        request.setStorCode(storCode);
        request.setStockDate(stockDate);
        request.setStockType(stockType);
        request.setOrganCode(organCode);
        request.setStat(stat);
        request.setVerfyStat(verfyStat);

        S019A response = storOrderService.findStockinPager(request);

        return new TabPager(response.getStockinInfos(), response.getTotalNum());
    }

    @RequestMapping(value = "/stockin/addStockin", method = RequestMethod.POST)
    public RspModel addStockin(@RequestBody S010R request){
        //赋值交易报文头
        TradeUtil.setHead(request);

        S010A response = storOrderService.addStockinBill(request);

        return new RspModel(response.getStockId());
    }

    @RequestMapping(value = "/stockin/getStockinDetailList", method = RequestMethod.GET)
    public TabPager getStockinDetailList(@RequestParam("stockId") Integer stockId){
        S029R request = new S029R();
        // 赋值交易报文头
        TradeUtil.setHead(request);
        request.setStockId(stockId);
        request.setPagination(false);

        // 调用查询入库单明细
        S029A response = storOrderService.findStockinDetail(request);
        return new TabPager(response.getStockDetailData(), response.getTotalNum());
    }

    @RequestMapping(value = "/stockin/editStockin", method = RequestMethod.POST)
    public RspModel editStockin(@RequestBody S012R request) {
        TradeUtil.setHead(request);

        S012A response = storOrderService.editStockinBill(request);
        return new RspModel(response.getStockId());
    }

    @RequestMapping(value = "/stockin/delStockin", method = RequestMethod.POST)
    public RspModel delStockin(@RequestParam("stockId") Integer stockId){
        S011R request = new S011R();
        TradeUtil.setHead(request);

        request.setStockId(stockId);
        S011A response = storOrderService.delStockinBill(request);
        return new RspModel(response.getStockId());
    }

    @RequestMapping(value = "/stockin/verfyPass", method = RequestMethod.POST)
    public RspModel verfyPass(@RequestParam("stockId") Integer stockId){
        S015R request = new S015R();
        TradeUtil.setHead(request);

        request.setStockId(stockId);
        request.setVerfyStat(VerfyStatEnum.VERFY_STAT_PASS.getCode());
        S015A response = storOrderService.verfyStockinBill(request);

        return new RspModel(response.getStockId());
    }

    @RequestMapping(value = "/stockin/verfyNopass", method = RequestMethod.POST)
    public RspModel verfyNopass(@RequestParam("stockId") Integer stockId, @RequestParam("verfyErrMsg") String verfyErrMsg){
        S015R request = new S015R();
        TradeUtil.setHead(request);

        request.setStockId(stockId);
        request.setVerfyStat(VerfyStatEnum.VERFY_STAT_FAIL.getCode());
        request.setVerfyErrMsg(verfyErrMsg);
        S015A response = storOrderService.verfyStockinBill(request);

        return new RspModel(response.getStockId());
    }
}
